#!/usr/bin/env python 
# -*- coding:utf-8 -*-

import pandas as pd
import requests
import ast

url = 'http://job.hengyirong.com/jobinfo/pageList'
data = {"jobGroup":3, "length":1000}
header = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7",
    "Connection": "keep-alive",
    "Cookie": "XXL_JOB_LOGIN_IDENTITY=3563643665626430353038363438653631323838666235356131303038633032",
    "Host": "job.hengyirong.com",
    "Upgrade-Insecure-Requests": "1",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"
}
res = requests.post(url,data,headers = header)
list = ast.literal_eval(res.text)
data = list['data']
for key, val in enumerate(data):
    if val['jobStatus']=='NONE':
        data[key]['状态']='开启'
    else:
        data[key]['状态']='关闭'
    cron = val['jobCron']
    #分割0 0 8,9,22 *  * ? 为列表
    crons = cron.split(' ')
    for v in crons:
       data[key]['秒'] = crons[0]
       data[key]['分'] = " "+crons[1]
       data[key]['时'] = " "+crons[2]
       data[key]['日'] = " "+crons[3]
       data[key]['月'] = crons[4]
       data[key]['周'] = crons[5]
       seconds = crons[2].split(',')
       for s in seconds:
           if s >= '1':data[key]['凌晨后'] = '是'

# print(data)
df = pd.DataFrame(data,columns=['id', 'author', 'jobDesc', 'glueType', '状态', 'alarmEmail', 'glueSource','jobCron','秒','分','时','日','月','周','凌晨后'])
df.to_csv('test.csv',index= False)